package com.dragon.modules.yuegou.service.impl.coupon;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.coupon.ParkApplyCheckRecordEntity;
import com.dragon.modules.yuegou.entity.system.UserEntity;
import com.dragon.modules.yuegou.mapper.coupon.ParkApplyCheckRecordMapper;
import com.dragon.modules.yuegou.model.coupon.ParkApplyCheckRecord;
import com.dragon.modules.yuegou.query.coupon.ParkApplyCheckRecordQuery;
import com.dragon.modules.yuegou.service.coupon.ParkApplyCheckRecordService;
import com.dragon.modules.yuegou.service.system.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 停车券审核记录表 服务实现
 *
 * @author ljf
 * @date 2019-08-06 10:38:00
 * @version 2.0
 */
@Service("coupParkApplyCheckRecordService")
public class ParkApplyCheckRecordServiceImpl
		extends ServiceImpl<ParkApplyCheckRecordMapper, ParkApplyCheckRecordEntity>
		implements ParkApplyCheckRecordService {

	@Autowired
	private UserService userService;

	@Override
	public List<ParkApplyCheckRecord> checkRecord(String parkApplyId) {
		ParkApplyCheckRecordQuery query = new ParkApplyCheckRecordQuery();
		query.parkApplyId().eq(parkApplyId);
		List<ParkApplyCheckRecordEntity> entities = baseMapper.selectList(query.toQueryWrapper());
		return entities.stream().map(ParkApplyCheckRecord::new).collect(Collectors.toList());
	}

	@Override
	public ParkApplyCheckRecord getLast(String id) {
		ParkApplyCheckRecord last = baseMapper.getLast(id);
		if (last != null) {
			String checkedBy = last.getCheckedBy();
			UserEntity user = userService.getById(checkedBy);
			last.setCheckByName(user.getNickName());
		}
		return last;
	}
}